module l2cache_arbiter
#(
    parameter ADDR_MEM_WIDTH = 32
) 
(
    input [ADDR_MEM_WIDTH-1:0]    addr_mem0,
    input [ADDR_MEM_WIDTH-1:0]    addr_mem1,

    input rqst_axi_s0,            // SLAVE 0 request signal
    input rqst_axi_s1,            // SLAVE 1 request signal
    input rqst_display_buf,       // Display buffer request siganl

    input [3:0] apb_config,      // Arbiter configuration
         

    output  grant_axi_s0,           // SLAVE 0 grant siganl
    output  grant_axi_s1,           // SLAVE 1 grant siganl
    output  grant_display_buf      // Display buffer grant siganl
);

`define ROUND_ROBIN 4'b0001

wire [2:0] req;
reg [2:0] grant;
reg [3:0] reg_arbiter;
reg [5:0] pointer_reg;

assign req = {rqst_axi_s0,rqst_axi_s1,rqst_display_buf};
assign grant_axi_s0      = grant[0];
assign grant_axi_s1      = grant[1];
assign grant_display_buf = grant[2];

//Combination always block
always @ (*) begin
    case (reg_arbiter)
    `ROUND_ROBIN : begin
            case (pointer_reg) // synopsys full_case parallel_case
                2'b00 : begin
                    if (req[0]) grant = 3'b001;
                    else if (req[1]) grant = 3'b010;
                    else if (req[2]) grant = 3'b100;
                    else grant = 3'b000;
                end

                2'b01 : begin
                    if (req[1]) grant = 3'b010;
                    else if (req[2]) grant = 3'b100;
                    else if (req[0]) grant = 3'b001;
                    else grant = 3'b000;
                end

                2'b10 : begin
                    if (req[2]) grant = 3'b100;
                    else if (req[0]) grant = 3'b001;
                    else if (req[1]) grant = 3'b010;
                    else grant = 3'b000;
                end

                default : begin
                    grant = 3'b000;
                end
            endcase
        end

        default : begin
            grant = 3'b000;
        end
    endcase
end

// Sequence always block updating register pointer_reg
always @(*)
begin
    if (grant != 3'b000 & reg_arbiter == `ROUND_ROBIN) begin
        if (pointer_reg == 2) begin
            pointer_reg = 5'b00000;
        end else begin
            pointer_reg = pointer_reg + 1'b1;
        end
    end
end


//Multiplexed outputs
always @(*)
begin
    case (grant)
        3'b001 : begin
        end
        
        3'b010 : begin
        end
        
        3'b100 : begin
        end
        
        default : begin
        end
    endcase
end

endmodule